use std::num::ParseIntError;

fn main() {
    println!("Hello, world!");
    let twenty = multiply_op("10", "2");
    print(twenty);

    let tt = multiply_op("10", "a");
    print(tt);
}
fn _multiply(fns: &str, sns: &str) -> Result<i32, ParseIntError> {
    match fns.parse::<i32>() {
        Ok(first_number) => match sns.parse::<i32>() {
            Ok(second_number) => Ok(first_number * second_number),
            Err(e) => Err(e),
        },
        Err(e) => Err(e),
    }
}

fn multiply_op(fns: &str, sns: &str) -> Result<i32, ParseIntError> {
    fns.parse::<i32>()
        .and_then(|fi| sns.parse::<i32>().map(|sn| fi * sn))
}

fn print(result: Result<i32, ParseIntError>) {
    match result {
        Ok(n) => println!("n is {}", n),
        Err(e) => println!("Error: {}", e),
    }
}
